<?php
namespace app\modules\Admin\models;

use Illuminate\Database\Eloquent\Model;

class dianpuwithdrawlogModel extends Model
{
	protected $table 		= 'dianpu_withdraw_log';
	public	  $primaryKey	= 'id';
	public $appends = ['event_name', 'oper_type_text', 'oper_type_user'];
    public $timestamps = false;

    protected static $allStatus = [
        'apply'=>'申请提现',
        'denied'=>'拒绝提现',
        'agree'=>'同意提现',
        'finished'=>'确认收款',
        'canceled'=>'取消提现',
        'paid'=>'已打款',
    ];
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public static function getAllStatus()
    {
        return self::$allStatus;
    }

    public function getEventNameAttribute()
    {
        $status_name = '';
        $statusCodes = array_keys(self::$allStatus);
        if(in_array($this->attributes['event'], $statusCodes)){
            $status_name = self::$allStatus[$this->attributes['event']];
        }
        return $status_name;
    }

    public function getOperTypeTextAttribute()
    {
        // admin=管理员,system=系统,user=用户
        switch ($this->attributes['oper_type']) {
            case 'admin':
                return '管理员';
            case 'system':
                return '系统';
            case 'user':
                return '用户';
            default:
                return '未知';
        }
    }

    public function dianpuwithdraw()
    {
        return $this->belongsTo(dianpuwithdrawModel::class, 'event_id', 'id');
    }

    public function getOperTypeUserAttribute()
    {
        switch ($this->attributes['oper_type']) {
            case 'admin':
                return \adminModel::query()->where('id', $this->attributes['oper_id'])->value('username');
            case 'system':
                return '系统';
            case 'user':
                return \memberModel::query()->where('id', $this->attributes['oper_id'])->value('nickname');
            default:
                return '未知';
        }
    }
}

